package org.formal.common.page;

import java.io.Serializable;
import java.util.List;
import com.github.pagehelper.Page;


/**
 * 分页类
 * @author jiangyan
 *
 * @param <T>
 */
public class Pagination<T> implements Serializable{

	private static final long serialVersionUID = 8656597559014685635L;
	/**
	 * 总页数
	 */
	private int total;
	/**
	 * 结果集
	 */
	private List<T> rows;    
	/**
	 * 第几页
	 */
	private int pageNum;    
	/**
	 *  每页记录数
	 */
	private int pageSize;    
	/**
	 *  总记录数
	 */
	private long records;
	
	public Pagination() {
		super();
	}
	
	/**
	 * 包装Page对象，因为直接返回Page对象，在JSON处理以及其他情况下会被当成List来处理，
	 * 而出现一些问题。
	 */
	public Pagination(List<T> rows) {
		if (rows instanceof Page) {
			Page<T> page = (Page<T>) rows;
			this.pageNum = page.getPageNum();
			this.pageSize = page.getPageSize();
			this.records = page.getTotal();
			this.total = page.getPages();
			this.rows = page;
		}
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public List<T> getRows() {
		return rows;
	}

	public void setRows(List<T> rows) {
		this.rows = rows;
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public long getRecords() {
		return records;
	}

	public void setRecords(long records) {
		this.records = records;
	}
}
